/** Globals used across the whole project
 *
 * This file contains global variables used at various places in the whole
 * project.
*/
//##############################################################################




/** PID parameters for the differen controllers */
volatile double pid_yaw [3];
volatile double pid_attitude [3];
volatile double pid_position [3];
//------------------------------------------------------------------------------




/** Quaternion describing the attitude of the quadrocopter */
volatile double quaternion [4];
//------------------------------------------------------------------------------




/** Rotation angles as sum of 1D rotations */
volatile double rot1D [3];
//------------------------------------------------------------------------------




/** Current orientation (computed from quaternion) */
volatile double orientation [3];
//------------------------------------------------------------------------------




/** Current speed */
volatile double speed [3];
//------------------------------------------------------------------------------




/** Current position */
volatile double position [3];
//------------------------------------------------------------------------------




/** Scaled sensor values */
volatile double itg [3];
volatile double adxl [3];
//------------------------------------------------------------------------------





/** Reference values */
volatile double attitude_reference [2];
volatile double yaw_reference;
//------------------------------------------------------------------------------




/** ID values */
volatile double pid_attitude_integral [2];
volatile double pid_attitude_last [2];
volatile double pid_yaw_integral;
volatile double pid_yaw_last;
volatile double pid_position_integral [3];
volatile double pid_position_last [3];
//------------------------------------------------------------------------------




/** Control parameters to enable and disable parts of the system */
volatile signed char ctl_engine;
volatile signed char ctl_calibration;
volatile signed char ctl_quaternion;
volatile signed char ctl_attitude;
volatile signed char ctl_yaw;
volatile signed char ctl_position;
//##############################################################################




/** Sets all globals listed here to their default values (which will be 0 in
 * the most cases
*/
void globals_set_default( void )
{
  pid_yaw[0] = pid_attitude[0] = pid_position[0] = 0;
  pid_yaw[1] = pid_attitude[1] = pid_position[1] = 0;
  pid_yaw[2] = pid_attitude[2] = pid_position[2] = 0;
  quaternion[0] = 1;
  quaternion[1] = quaternion[2] = quaternion[3] = 0;
  itg[0] = adxl[0] = 0;
  itg[1] = adxl[1] = 0;
  itg[2] = adxl[2] = 0;
  attitude_reference[0] = 0;
  attitude_reference[1] = 0;
  yaw_reference = 0;
  pid_attitude_integral[0] = 0;
  pid_attitude_integral[1] = 0;
  pid_attitude_last[0] = 0;
  pid_attitude_last[1] = 0;
  pid_yaw_integral = 0;
  pid_yaw_last = 0;
  pid_position_integral[0] = 0;
  pid_position_integral[1] = 0;
  pid_position_integral[2] = 0;
  pid_position_last[0] = 0;
  pid_position_last[1] = 0;
  pid_position_last[2] = 0;
  ctl_engine = 1;
  ctl_calibration = 0;
  ctl_quaternion = 1;
  ctl_attitude = 1;
  ctl_yaw = 1;
  ctl_position = 1;
}
//##############################################################################




